/**
 * Created by Chen on 2016/2/27.
 */
/**
 * Created by win on 2016/1/27.
 */
define(function(require, exports, module){

    var $ = require('jquery');
    require('jquery.fileupload');
    require('jquery.validate');
    require('jquery.layer');
    require('bootstrap');

    $("#paper-submit").click(function(){
        var $form = $("#paper-form");
        if(!$form.valid()){
            return;
        }

        var postData = $form.serialize();

        var posting = $.post($CONFIG.base_url + "/api/paper/save", postData);
        posting.done(function(data) {
            layer.msg('保存成功', {
                time: 4000 //4s后自动关闭
            });
            window.location.href = $CONFIG.base_url + "/admin/paper/manage";
        });
    });

    $('#fileUpload').fileupload({
        url :$CONFIG.base_url+"/commons/attachment/upload",
        dataType:"json",
        formData:{uid:1},
        add:function(e,data){
            var uploadFile = data.files[0];
            var goUpload = true;
            if (uploadFile.size>1024000) {
                goUpload = false;
                alert("file is too large!");
            }
            if (goUpload) {
                data.submit();
            }
        },
        done:function(e,result) {
            $("#attachment").val(JSON.stringify(result.result.id));
        }
    });

});
